﻿using System;
using System.Collections.Generic;

//泛型链表类
public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}

public class GenerList<T>
{
    private Node<T> head;
    private Node<T> tail;

    public GenerList()
    {
        head = tail = null;
    }

    public Node<T> Head
    {
        get => head;
    }

    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (tail == null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
    }

    public void ForEach(Action<T> action)
    {
        Node<T> code = head;
        while (code != null)
        {
            action(code.Data);
            code = code.Next;
        }
    }
}

    

public class Program01
{
    static void Main(string[] args)
    {
        GenerList<int> intList = new GenerList<int>();
        for (int i = 0; i < 10; i++)
        {
            intList.Add(i);
        }
        int max = intList.Head.Data;
        int min = intList.Head.Data;
        int sum = 0;
        intList.ForEach(x => Console.WriteLine(x));
        intList.ForEach(x => max = (max > x) ? max : x);
        Console.WriteLine("最大值是："+max);
        intList.ForEach(x => min = (min < x) ? min : x);
        Console.WriteLine("最小值是：" +min);
        intList.ForEach(x => sum += x);
        Console.WriteLine("和为："+sum);
    }
}